package com.nidu.demo.dict.model;

import com.alibaba.cola.exception.BizException;
import com.nidu.demo.base.BaseDeletableEntity;
import com.nidu.demo.base.BaseEntity;
import com.nidu.demo.base.BaseStatusEntity;
import com.nidu.demo.common.enums.BooleanEnum;
import com.nidu.demo.common.enums.StatusEnum;
import com.nidu.demo.common.exception.ErrorCodeConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 字典类型领域对象
 *
 * @author auto
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class DictType extends BaseEntity implements BaseStatusEntity, BaseDeletableEntity {

    /**
     * 主键ID
     */
    private Long id;

    /**
     * 字典类型名称
     */
    private String name;

    /**
     * 字典类型
     */
    private String type;

    /**
     * 排序值
     */
    private Integer sortOrder;

    /**
     * 状态
     */
    private Integer status;

    /**
     * 是否删除
     */
    private Boolean deleted;

    @Override
    public void isDeleted() {
        if (BooleanEnum.TRUE.getValue().equals(this.deleted)) {
            throw new BizException(ErrorCodeConstants.DICT_TYPE_NOT_FOUND.getCode(), ErrorCodeConstants.DICT_TYPE_NOT_FOUND.getMessage());
        }
    }

    @Override
    public void isDisable() {
        if (StatusEnum.DISABLE.getValue().equals(this.status)) {
            throw new BizException(ErrorCodeConstants.DICT_TYPE_STATUS_DISABLE.getCode(), ErrorCodeConstants.DICT_TYPE_STATUS_DISABLE.getMessage());
        }
    }

    public static DictType create(String name, String type, Integer sortOrder) {
        DictType dictType = new DictType();
        dictType.setName(name)
                .setType(type)
                .setSortOrder(sortOrder);
        return dictType;
    }

    public static DictType update(Long id, String name, String type, Integer sortOrder) {
        DictType dictType = new DictType();
        dictType.setId(id)
                .setName(name)
                .setType(type)
                .setSortOrder(sortOrder);
        return dictType;
    }

}
